using System;

namespace yyycommon
{
	
	[Serializable]
	public class ObfuscatedNumber
	{

		public static double decodeNum(byte[] bytearr)
		{
			return BitConverter.ToDouble(bytearr, 0) + BitConverter.ToDouble(bytearr, 8);
		}

		public static void encodeNum(double value, byte[] outArr)
		{
			double num = new Random().NextDouble() * value;
			Array.Copy(BitConverter.GetBytes(num), outArr, 8);
			Array.Copy(BitConverter.GetBytes(value - num), 0, outArr, 8, 8);
			Console.WriteLine("encode " + value + "=>" + decodeNum(outArr));
		}

		private byte[] _values;

		public double Value
		{
			get
			{
				return decodeNum(_values);
			}
			set
			{
				encodeNum(value, _values);
			}
		}

		public void copyArr(byte[] value){
			this._values = value;
		}

		public byte[] readArr() {
			return this._values;
		}

		public ObfuscatedNumber(double initialValue = 0.0)
		{
			_values = new byte[16];
			Value = initialValue;
		}

		public override string ToString()
		{
			return Value.ToString();
		}
	}
}
